package com.thinkgem.jeesite.modules.vote.web;

import com.thinkgem.jeesite.modules.cms.entity.Site;
import com.thinkgem.jeesite.modules.cms.utils.CmsUtils;
import com.thinkgem.jeesite.modules.sys.entity.vote.VoteCandidate;
import com.thinkgem.jeesite.modules.sys.service.vote.VoteCandidateService;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
import com.thinkgem.jeesite.modules.vote.entity.Candidate;
import com.thinkgem.jeesite.modules.vote.entity.VoteQuestion;
import org.apache.shiro.authz.annotation.RequiresUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by zxbsp on 2017/5/19.
 */
@Controller
@RequestMapping(value = "${frontPath}/vote")
public class VoteController {

    @Autowired
    private VoteCandidateService voteCandidateService;

    /**
     * 党员投票
     */
    @RequiresUser
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String vote(Model model, HttpServletRequest request){
        Object obj = request.getSession().getAttribute("user");
        if (obj == null){
            //返回登录页面
            //return null;
        }
        Site site = CmsUtils.getSite(Site.defaultSiteId());

        List<VoteQuestion> voteQuestions = new ArrayList<VoteQuestion>(10);
        voteQuestions.add(new VoteQuestion( "ques1","对党的路线方针政策的认识和执行情况"));
        voteQuestions.add(new VoteQuestion("ques2","对党的认识和入党动机"));
        voteQuestions.add(new VoteQuestion("ques3","思想品德和职业道德"));
        voteQuestions.add(new VoteQuestion("ques4","原则性和组织纪律性"));
        voteQuestions.add(new VoteQuestion("ques5","为人民服务思想和先模作用"));
        voteQuestions.add(new VoteQuestion("ques6","本职业务能力"));
        voteQuestions.add(new VoteQuestion("ques7","顾全大局和不计较个人得失"));
        voteQuestions.add(new VoteQuestion("ques8","实事求是"));
        voteQuestions.add(new VoteQuestion("ques9","开展批评与自我批评"));
        voteQuestions.add(new VoteQuestion("ques10","团结同志"));

//        List<Candidate> candidates = new ArrayList<Candidate>(5);
//        candidates.add(new Candidate("cd1","郑雪冰"));
//        candidates.add(new Candidate("cd2", "马清波"));
//        candidates.add(new Candidate("cd3","林永华"));
//        candidates.add(new Candidate("cd4","江平"));

        List<VoteCandidate> candidates = voteCandidateService.findList(new VoteCandidate());

        model.addAttribute("questions", voteQuestions);
        model.addAttribute("candidates", candidates);
        model.addAttribute("loginUser", UserUtils.getUser());
        return "modules/cms/front/themes/" + site.getTheme() + "/votepage";
    }
}
